function [MME_initial_point_num, MME_time, MME_aggregation_flag, ...
          NLLS_initial_point_num, NLLS_time, NLLS_metric_flag, parallel_flag] = HPZ_Interface_Optimization_settings(action)
% The max number of convergance points MME
% MME_initial_point_num;
%
%% TO BE DONE
% Time (minutes) that user want to spend on running the code on the machine
% MME_time
%
% Which aggregation method would you like to use in the estimation?
% Maximum Waste:
% aggregation_flag = 1
% Mean Waste:
% aggregation_flag = 2
% Sum of Square Wastes:
% aggregation_flag = 3
%
% The max number of convergance points NLLS
% NLLS_initial_point_num;
%
%% TO BE DONE
% Time (minutes) that user want to spend on running the code on the machine
% NLLS_time
%
% Would you like to use Euclidean metric (else Choi et al. (2007) metric is
% applied)?)
% NLLS_metric_flag = 1 ('Yes')
% NLLS_metric_flag = 2 ('No')
    
    %% initialization
    MME_initial_point_num = 3;
    MME_time = Inf;
    MME_aggregation_flag = 0;

    NLLS_initial_point_num = 5;
    NLLS_time = Inf;
    NLLS_metric_flag = 0;
    
    parallel_flag = true;

    %% NLLS
    if action == 2

        enable_string_NLLS = 'on';

        enable_string_MME = 'off';
        MME_initial_point_num = 0;
        MME_time = 0;
        MME_aggregation_flag =0;

    %% MME
    elseif action == 3

        enable_string_NLLS = 'off';
        NLLS_initial_point_num = 0;
        NLLS_time = 0;
        NLLS_metric_flag = 0;

        enable_string_MME = 'on';
    else
        return
    end

    % create the gui figure
    sz = [380 470]; % figure size
    screensize = get(0,'ScreenSize');
    xpos = ceil((screensize(3)-sz(2))/2); % center the figure on the
    ypos = ceil((screensize(4)-sz(1))/2); % center the figure on the

    %% Optimization Setting
    S.fh = figure('units','pixels',...
                  'position',[xpos, ypos, sz(2), sz(1)],...
                  'menubar','none',...
                  'name','Optimization Settings',...
                  'numbertitle','off',...
                  'resize','off');

    %% Optimization settings MME
    S.label_MME = uicontrol('style','text',...
                     'units','pix',...
                     'position',[10 350 175 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',12,'fontweight','bold',... 
                     'string','Money Metric Method');

    S.initial_points_MME = uicontrol('style','text',...
                     'enable', enable_string_MME, ...
                     'units','pix',...
                     'position',[15 320 150 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',10,...
                     'string','Number of convergence points:');

    S.initial_points_MME_pop = uicontrol('style','pop',...
                      'units','pixels',...
                      'enable', enable_string_MME, ...
                      'position',[170 305 40 40],...
                      'string',{'3','4','5','6','7','8','9','10'});

    S.estimated_time_MME_label = uicontrol('style','text',...
                     'units','pix',...
                     'enable', enable_string_MME, ...
                     'position',[220 320 150 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',10,...
                     'string','Allocated time (minutes):');

    S.estimated_time_MME_text = uicontrol('style','edit',...
                     'enable', enable_string_MME, ...
                     'units','pix',...
                     'position',[375 330 80 25],...
                     'backgroundc','white',...
                     'fontsize',10);


    %% Aggregation MME
    S.ed_MME = uicontrol('style','edit',...
                     'unit','pix',...
                     'enable', enable_string_MME, ...
                     'position',[20 290 170 20],...
                     'backgroundc',get(S.fh,'color'),...
                     'string','Aggregation  Method');

    S.bg_MME = uibuttongroup('units','pix',...
                         'pos',[20 250 430 40]);

    S.Aggregation_MME_rd(1) = uicontrol(S.bg_MME,...
                        'enable', enable_string_MME, ...
                        'style','rad',...
                        'unit','pix',...
                        'position',[10 5 160 30],...
                        'string','Maximum Waste');

    S.Aggregation_MME_rd(2) = uicontrol(S.bg_MME,...
                        'enable', enable_string_MME, ...
                        'style','rad',...
                        'unit','pix',...
                        'position',[145 5 250 30],...
                        'string','Mean Waste');

    S.Aggregation_MME_rd(3) = uicontrol(S.bg_MME,...
                        'enable', enable_string_MME, ...                    
                        'style','rad',...
                        'unit','pix',...
                        'position',[255 5 170 30],...
                        'string','Sum of Squares Wastes');         
    %% End of MME settings


    %% Optimization settings NLLS
    S.label_NLLS = uicontrol('style','text',...
                     'units','pix',...
                     'position',[15 190 190 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',12,'fontweight','bold',... 
                     'string','Nonlinear Least Squares');

    S.initial_points_NLLS = uicontrol('style','text',...
                     'enable', enable_string_NLLS, ...
                     'units','pix',...
                     'position',[15 160 150 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',10,...
                     'string','Number of convergence points:');

    S.initial_points_NLLS_pop = uicontrol('style','pop',...
                      'enable', enable_string_NLLS, ...
                      'units','pixels',...
                      'position',[170 145 40 40],...
                      'string',{'5','6','7','8','9','10'});

    S.estimated_time_NLLS_label = uicontrol('style','text',...
                     'enable', enable_string_NLLS, ...
                     'units','pix',...
                     'position',[220 160 150 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',10,...
                     'string','Allocated time (minutes):');

    S.estimated_time_NLLS_text = uicontrol('style','edit',...
                     'units','pix',...
                     'enable', enable_string_NLLS, ...
                     'position',[375 170 80 25],...
                     'backgroundc','white',...
                     'fontsize',10);

    %% Metric Method NLLS
    S.ed_NLLS = uicontrol('style','edit',...
                     'enable', enable_string_NLLS, ...
                     'unit','pix',...
                     'position',[20 130 170 20],...
                     'backgroundc',get(S.fh,'color'),...
                     'string','Metric  Selection');

    S.bg_NLSS = uibuttongroup('units','pix',...
                         'pos',[20 90 430 40]);

    S.metric_NLLS_rd(1) = uicontrol(S.bg_NLSS,...
                        'style','rad',...
                        'enable', enable_string_NLLS, ...
                        'unit','pix',...
                        'position',[40 5 160 30],...
                        'string','Euclidean metric');

    S.metric_NLLS_rd(2) = uicontrol(S.bg_NLSS,...
                        'style','rad',...
                        'enable', enable_string_NLLS, ...
                        'unit','pix',...
                        'position',[220 5 175 30],...
                        'string','Choi et al. (2007) metric');
                    
                    
    S.parallel_label = uicontrol('style','text',...
                     'units','pix',...
                     'position',[15 40 150 30],...
                     'backgroundc',get(S.fh,'color'),...
                     'fontsize',12,'fontweight','bold',... 
                     'string','Parallel Processing');
                 
    S.parallel_label_ch = uicontrol('style','check',...
                     'unit','pix',...
                     'position',[175 47 275 25],...
                     'string','Use matlab parallel computing package.',...
                     'value', 1.0, ...
                     'fontsize',10);


    S.pb = uicontrol('style','push',...
                     'unit','pix',...
                     'position',[175 5 100 30],...
                     'string','OK', ...
                     'callback',{@pb_call,S});

    uiwait(S.fh)  % Prevent all other processes from starting until closed.

    pause(0);
    
    %% OK button
    function [] = pb_call(varargin)
        
        % Callback for the popup.
        S = varargin{3};  % Get the structure.

        if strcmpi(get(S.initial_points_MME, 'enable'), 'off') % NLLS
            rd_vals_NLLS = get (S.metric_NLLS_rd(:), 'value');
            if rd_vals_NLLS{1} == 1;
                % Euclidean
                NLLS_metric_flag = 1;
            else
                % Choi (2007) metirc
                NLLS_metric_flag = 2;
            end % end switch
            
            % set thte number of convergance points for NLLS
            P_NLLS = get(S.initial_points_NLLS_pop,{'string','val'});  % Get the users choice.
            NLLS_initial_point_num = str2num(P_NLLS{1}{P_NLLS{2}});
            
            if strcmp(get(S.estimated_time_NLLS_text,'string'), '')
                NLLS_time = Inf;
            else
                NLLS_time = str2num(get(S.estimated_time_NLLS_text,'string'));
            end

        else % MME
            rd_vals_MME = get (S.Aggregation_MME_rd(:), 'value');
            if rd_vals_MME{1} == 1
                    % Max Waste
                    MME_aggregation_flag = 1;

            elseif rd_vals_MME{2} == 1
                    % Mean Waste
                    MME_aggregation_flag = 2;

            else
                    % Sum of Squares Wastes
                    MME_aggregation_flag = 3;
            end % end of switch
            
            % set thte number of convergance points MME
            P_MME = get(S.initial_points_MME_pop,{'string','val'});  % Get the users choice.
            MME_initial_point_num = str2num(P_MME{1}{P_MME{2}});
            
            if strcmp(get(S.estimated_time_MME_text,'string'), '') 
                MME_time = Inf;
            else
                MME_time = str2num(get(S.estimated_time_MME_text,'string'));
            end

        end % end of if

        if get(S.parallel_label_ch, 'value') == 1.0 % Parallel Computing
            % Use matlabpool
            parallel_flag = true;
        else
            % Use serial version
            parallel_flag = false;
        end
        
        % close the window
        close(S.fh);

    end % end of call back function


end % end of function